package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName: OrderMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author 臧洁
 * @Create 2025/4/11 14:28
 * @Version 1.0
 */
@Mapper
public interface OrderMapper {
    /**
     * 向订单表中插入一条订单数据
     * @param orders
     */
    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from sky_take_out.orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询历史订单信息
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     */
    @Select("select * from sky_take_out.orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 根据状态，分别查询出待接单、待派送、派送中的订单数量
     * @param
     * @return
     */
    @Select("select count(id) from sky_take_out.orders where status=#{status}")
    Integer countStatus(Integer status);

    @Select("select * from sky_take_out.orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /**
     * 根据订单编号和用户名查找订单
     * @param outTradeNo
     * @param userId
     * @return
     */
    @Select("select * from sky_take_out.orders where number=#{outTradeNo} and user_id=#{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);

    /**
     * 营业额统计,动态查询
     * @param map
     * @return
     */

    Double sumByMap(Map map);

    /**
     * 查询订单数目
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 查询销量排名top10接口
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSaleTop10(LocalDateTime begin, LocalDateTime end);
}
